﻿Namespace TextFileFunctions

    Public Module mTextFileFunctions

        Public Function ReadNextValue(ByRef line As String) As String

            Dim R As String

            line = Trim(line)

            If Left(line, 1) = Chr(34) Then
                R = Mid(line, 2, InStr(2, line, Chr(34)) - 2)
                line = Right(line, (line.Length - R.Length) - 2)
            ElseIf InStr(line, " ") > 0 Then
                R = Left(line, InStr(line, " ") - 1)
                line = Right(line, line.Length - R.Length - 1)
            ElseIf InStr(line, vbCrLf) > 0 Then
                Else
                R = line
                line = ""
            End If

            Return Trim(R)

        End Function

        Public Function ReadHTTPHeader(ByRef line As String) As String

            Dim R As String

            R = Left(line, InStr(line, vbCrLf) - 1)
            line = Right(line, line.Length - R.Length - 1)

            Return r

        End Function

        Public Sub TrimLineTabs(ByRef line As String)

            If line Is Nothing Then Exit Sub
            If line.Length = 0 Then Exit Sub


            line = Replace(line, Chr(9), Chr(32))

            'make all spaces 1 space long
            Dim it As Integer = 1
            Dim trim As Boolean
            Dim str As String = ""

            Do Until it > line.Length
                If Not trim Or (trim And Not (Mid(line, it, 1) = " ")) Then
                    str &= Mid(line, it, 1)
                End If
                trim = (Mid(line, it, 1) = " ")
                it += 1
            Loop
            line = str
            '//

        End Sub

    End Module

End Namespace
